<template>
  <div class="certification">
    <p>为响应国家相关主管部门近期发文要求净化网络环境，规范游戏市场的号召，根据相关规定，代理商即日起需要进行实名认证后才可使用代理商后台功能，请您及时进行实名制认证，感谢您的支持与理解！</p>
    <p>我司将坚决拥护净网行动，愿与广大用户一起营造健康绿色的娱乐环境！</p>
    <div class="info">
      <div>
        <label for="name">真实姓名：</label>
        <input type="text" id="name" placeholder="请输入真实姓名" v-model="name">
      </div>
      <div>
        <label for="number">身份证号：</label>
        <input type="text" id="number" placeholder="请输入身份证号" v-model="number">
      </div>
    </div>
    <agent-button class="certification_btn" :disabled="btnEnable" @btnClick="btnClick">认证</agent-button>
  </div>
</template>

<script>
import AgentButton from "../../components/common/AgentButton.vue";
import { isIDCard, getUrlString } from "../../scripts/utils.js";
export default {
  data() {
    return {
      name: "",
      number: ""
    };
  },
  components: {
    AgentButton
  },
  created() {
    this.userInfo = this.apiService.getLocalData("userInfo");
  },
  computed: {
    btnEnable() {
      if (this.name && this.number) {
        return false;
      }
      return true;
    }
  },
  methods: {
    btnClick() {
      let uid = getUrlString("agentId") || this.userInfo.user_id;
      if (this.name.length < 2) {
        return this.$vux.toast.text("请输入真实姓名");
      }
      if (isIDCard(this.number)) {
        this.apiService.user
          .certification({
            realityname: this.name,
            idnumber: this.number,
            agentid: uid,
            actiontype: 1
          })
          .then(res => {
            this.$vux.toast.text("感谢您的配合！");
            /**
             * 如果本地有user_id说明是登录，直接跳到购卡页
             * 没有user_id说明是注册，跳到主页
             */
            if (getUrlString("agentId")) {
              this.$router.push("/login");
            } else {
              this.userInfo.iscertification = 0;
              this.apiService.setLocalData("userInfo", this.userInfo);
              this.$router.push("/toBuyCard");
            }
          });
      } else {
        this.$vux.toast.text("身份证号码输入有误");
      }
    }
  }
};
</script>

<style scoped>
.certification {
  background-color: #fff;
  color: var(--word-color);
  height: 100%;
  padding: 0.5rem 0.2rem 0;
}
.certification p {
  text-indent: 2em;
}
.info {
  margin-top: 1rem;
}
.info div {
  margin: 0.2rem 0;
  text-align: center;
}
.info div input {
  border: 1px solid var(--border-color);
  border-radius: 0.1rem;
  font-size: 0.3rem;
  padding: 0.1rem 0 0.1rem 0.1rem;
  width: 4rem;
}
.certification_btn {
  margin-top: 0.5rem;
}
</style>

